<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<script type="text/javascript">

	function getHttpObj() {
		var xmlhttp;
        	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
	            xmlhttp = new XMLHttpRequest();
	        } else {// code for IE6, IE5
	            xmlhttp = new window.ActiveXObject("Microsoft.XMLHTTP");
	        }
		return xmlhttp;
	}

	function dumpDict(dict)
	{
		str = "<ul>";
		for (var item in dict) {
			if (dict[item] instanceof Object) {
				str += "<li>"+item+":" + dumpDict(dict[item]) + "</li>";
			} else {
				str += "<li>"+item +":" +dict[item] + "</li>"
			}
		}
		str += "</ul>";
		return str;
	}

   function showMap(str) {
	var dompos = document.getElementById(str);
	if (dompos.innerHTML != "") {
		dompos.innerHTML = "";
		return;
	}
	var xmlhttp = getHttpObj();
	xmlhttp.onreadystatechange = function () {
		if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
			dompos.innerHTML  = '<img src="/maps/'+ str + '/minimap" />';
			dompos.innerHTML += '<img src="/maps/'+ str + '/heightmap" />';
			dompos.innerHTML += '<img src="/maps/'+ str + '/metalmap" />';
			var items = JSON.parse(xmlhttp.responseText);
			dompos.innerHTML += dumpDict(items);
		}
	}
        xmlhttp.open("GET","/maps/" + str + "/mapinfo",true);
        xmlhttp.send();
   }

    function showResult(str) {
        var xmlhttp = getHttpObj();
        if (str.length === 0) {
		var dompos = document.getElementById("items");
            dompos.innerHTML = "";
            dompos.style.border = "0px";
            return;
        }
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
		var dompos = document.getElementById("items");
		var items = JSON.parse(xmlhttp.responseText);
		dompos.innerHTML = "";
		for (var item in items) {
			var name = items[item];
			dompos.innerHTML += '<div><img alt="'+name+'" src="/maps/'+name+'/minimap_thumb" onClick="showMap(\'' + name + '\');"/><div id="' + name + '"></div></div>';
		}
		//document.getElementById("items").style.border = "1px solid #A5ACB2";
            }
        }
        xmlhttp.open("GET",str,true);
        xmlhttp.send();
    }
	function reloadUnitsync() {
		var xmlhttp = getHttpObj();
		xmlhttp.open("GET", "/system/reload" ,true);
		xmlhttp.send();
	}
showResult("/maps");
//-->
</script>
</head>
<body>
<div>
<h1>lslextract</h1>
<p>
lslextract is a tool to extract metadata from spring engine content files
</p>
<h2>homepage</h2>
<a href="https://github.com/spring/pr-downloader">https://github.com/spring/pr-downloader</a>
</div>
<div>
<h2>List of local content files</h2>
<p>(click on the item to show more info)</p>
<a href="#" onClick="reloadUnitsync();">Reload unitsync</a>
<div id="items">
</div>
</div>
</body>
</html>

